package com.china.springbootmybatis.commons;

import java.io.Serializable;

/**
 * @description:
 * @author: china@shanjun.wang
 * @create: 2019-10-25 14:02
 **/
public class Rtn implements Serializable {
    private int code;
    private String msg;
    private Object data;

    public static Rtn success() {
        return new Rtn(ErrorEnum.SUCCESS.getCode(), ErrorEnum.SUCCESS.getMsg(), null);
    }

    public static Rtn success(Object data) {
        if (data != null) {
            return new Rtn(ErrorEnum.SUCCESS.getCode(), ErrorEnum.SUCCESS.getMsg(), data);
        }
        return new Rtn(ErrorEnum.FAIL.getCode(), ErrorEnum.FAIL.getMsg(), null);

    }

    public static Rtn fail() {
        return new Rtn(ErrorEnum.FAIL.getCode(), ErrorEnum.FAIL.getMsg(), null);
    }

    public static Rtn fail(ErrorEnum errorEnum) {
        return new Rtn(errorEnum.getCode(), errorEnum.getMsg(), null);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Rtn(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
}
